<?php

namespace app\admin\model;

use think\Model;

class AuthGroup extends Model
{
  protected $table = 'a_auth_group';
  protected $pk    = 'id';
  protected $autoWriteTimestamp = true;

  // 取得所有分组
  public function getAllGroup(){
    //->where('status',1)
   return $this->field('id,title,is_admin,remark')->order('id', 'desc')->select();
  }

  // 取得指定分组id的名字
  public function getGroupTitle($group_id){
   return $this->where('id',$group_id)->field('title')->find();
  }

  //新增组
  public function addGroup($data){
   return $this->data($data)->allowField(true)->save();
  }

  //取出指定组
  public function getGroup($id){
    return $this->where('id',$id)->field('id,title,is_admin,remark,rules,status')->find();
  }

  //更新用户组信息
  public function updateGroup($data,$id){
    return $this->allowField(true)->save($data,['id'=>$id]);
  }

  public function deleteGroup($id){
    $ru = $this->destroy($id);
    if($ru){
        AuthGroupAccess::destroy(['group_id'=>$id]);

      return true;
    }
     return false;
  }

    /*
    批量删除
  */
  public function deleteAll($id)
  { 
    
    return $this->destroy($id);
  }

}
